//获取APP的实例
var util = require("../../utils/util.js")

var app = getApp();
Page({
  data: {
    isLogin: false,
    userInfo: null,
    headImg: null,
    btn: [
      {
        name: '积分管理',
        url: "../../images/more.png",
        urlTo: "../pains/pains"
      }, {
        name: '我的优惠券',
        url: "../../images/more.png",
        urlTo: "../coupons/coupons"
      }, {
        name: '关于我们',
        url: "../../images/more.png",
        urlTo: "../aboutos/aboutos"
      }, {
        name: "邀请好友",
        url: "../../images/more.png",
        urlTo: "../invitation/invitation"
      }
    ],
    btn1: [
      {
        name: "全部",
        url: "../../images/wait2.png"
      }, {
        name: "等待接单",
        url: "../../images/wait1.png"
      }, {
        name: "已完成",
        url: "../../images/wait3.png"
      }, {
        name: "已取消",
        url: "../../images/wait4.png"
      }, {
        name: "待评价",
        url: "../../images/wait5.png"
      }],
    screen: {
      height: '',
      width: ""
    },
    hasOrder: false,
    orderList: ""
  },
  registandlogin: function (event) {   // 登录跳转
    wx.navigateTo({
      url: '../login/login'
    })
  },
  onLoad: function () {
    var that = this

    wx.getSystemInfo({
      success: function (res) {
        // success
        that.setData({
          screen: {
            height: res.windowHeight + 'px',
            winth: res.windowWidth + 'px'
          }
        })
      }
    })
  },
  urlTo: function (event) {
    // console.log(event)
    var url = event.currentTarget.dataset.url
    if (url != "../aboutos/aboutos") {
      var isDo = judge(this.data.isLogin)
      if (isDo) {
        wx.navigateTo({
          url: url
        })
      }
    } else {
      wx.navigateTo({
        url: url
      })
    }

  },
  myOrder: function (event) {   // 跳转至订单管理页面
    var that = this
    var isDo = judge(that.data.isLogin)
    if (isDo) {
      wx.navigateTo({
        url: '../myOrder/myOrder?uid=' + that.data.userInfo.uid
      })
    }
  },
  navTo: function (event) {    // 跳转至指定的订单管理页面
    var id = event.currentTarget.id
    var title = event.currentTarget.dataset.title;
    var that = this
    var isDo = judge(that.data.isLogin)
    if (isDo) {
      wx.navigateTo({
        url: '../myOrder/myOrder?index=' + id + '&uid=' + this.data.userInfo.uid
      })
    }
  },
  onShow: function () {   // 页面显示
    var that = this
    var aaa = wx.getStorageSync("userInfo");
    if (aaa) {
      this.setData({
        isLogin: true,
        userInfo: aaa
      })
    }
    // util.pushMess(aaa.uid, that)
  },
  logout: function () {   // 退出登录
    var that = this
    wx.setStorage({
      key: 'userInfo',
      data: null,
      success: function (res) {
        // success
        that.setData({
          isLogin: false
        })
        wx.navigateTo({
          url: '../login/login'
        })
      }
    })
  },
  // 添加设置页面——更改人：大鑫
  setting: function () {   // 设置按键
    wx.navigateTo({
      url: '../settings/settings',
    })
  },
  navToMes: function () {   // 跳转到超级管理员页面
    wx.navigateTo({
      url: '../administrate/administrate'
    })
  }
})

function judge(isLogin) {  // 判断目前的登录状态
  if (!isLogin) {
    wx.showModal({
      showCancel: false,
      content: "您还未登录，请先登录",
      success: function () {
        wx.navigateTo({
          url: '../login/login'
        })
      }
    })
    return false;
  } else {
    return true;
  }
}